import { request } from '@umijs/max';

/**
 * 用户登录
 * @param params
 */
export async function userLogin(params: any) {
  return request('/user/login', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/**
 * 用户注册
 * @param params
 */
export async function userRegister(params: any) {
  return request('/user/register', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/**
 * 用户注销
 */
export async function userLogout() {
  return request('/user/logout', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
  });
}

/**
 * 获取当前登录用户
 */
export async function getLoginUser() {
  return request('/user/get/login', {
    method: 'GET',
  });
}

/**
 * 修改用户密码
 * @param params
 */
export async function updateUserPassword(params: {
  oldPassword: string;
  newPassword: string;
  checkPassword: string;
}) {
  return request('/user/update/password', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/**
 * 分页获取用户列表
 * @param params
 */
export async function listUserByPage(params: {
  current: number;
  pageSize: number;
  sortField?: string;
  sortOrder?: string;
}) {
  return request('/user/list/page', {
    method: 'GET',
    params,
  });
}

/**
 * 创建用户
 * @param params
 */
export async function addUser(params: any) {
  return request('/user/add', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/**
 * 更新用户信息
 * @param params
 */
export async function updateUser(params: any) {
  return request('/user/update', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/**
 * 删除用户
 * @param params
 */
export async function deleteUser(params: { id: number }) {
  return request(`/user/delete`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}
